package com.dorm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dorm.entity.Attendance;
import com.dorm.mapper.AttendanceMapper;
import com.dorm.service.AttendanceService;
import org.springframework.stereotype.Service;

import java.time.LocalDate;

/**
 * 考勤服务实现类
 */
@Service
public class AttendanceServiceImpl extends ServiceImpl<AttendanceMapper, Attendance> implements AttendanceService {

    @Override
    public Page<Attendance> pageQuery(Integer pageNum, Integer pageSize, Long studentId, String type, LocalDate startDate, LocalDate endDate) {
        Page<Attendance> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<Attendance> wrapper = new LambdaQueryWrapper<>();
        
        if (studentId != null) {
            wrapper.eq(Attendance::getStudentId, studentId);
        }
        if (type != null && !type.isEmpty()) {
            wrapper.eq(Attendance::getType, type);
        }
        if (startDate != null) {
            wrapper.ge(Attendance::getDate, startDate);
        }
        if (endDate != null) {
            wrapper.le(Attendance::getDate, endDate);
        }
        
        wrapper.orderByDesc(Attendance::getDate);
        return page(page, wrapper);
    }
}

